﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace LittleMonkey.Communication
{
    public class HTTPGetReq
    {
        WebClient client = null;
        public HTTPGetReq()
        {
            client = new WebClient();
        }
        public void request(string URL, Dictionary<string, string> args, HTTPResponse mres)
        {
            string parms = "";
            foreach (KeyValuePair<String, String> entry in args)
            {
                if (parms.Length > 1)
                {
                    parms = parms + "&";
                }
                parms = parms + entry.Key + "=" + entry.Value;
            }
            URL = URL + parms;
            try
            {
                Stream data = client.OpenRead(URL);
                StreamReader reader = new StreamReader(data);
                string s = reader.ReadToEnd();
                data.Close();
                reader.Close();
                mres.getResponse(s);
            }
            catch (System.Exception ex)
            {
                mres.getResponse(null);
            }
        }

    }
}
